package com.muqi.app.qlearn.adapter;

import java.util.List;

import com.bumptech.glide.Glide;
import com.muqi.app.qlearn.modles.MediaInfo;
import com.muqi.app.qlearn.student.R;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

public class HomeWKPicsAdapter extends BaseAdapter {
	private Context context;
	private List<MediaInfo> listData;
	private PicsItemClickListener listener = null;

	public HomeWKPicsAdapter(Context context, List<MediaInfo> listData, PicsItemClickListener listener) {
		this.context = context;
		this.listData = listData;
		this.listener = listener;
	}

	@Override
	public int getCount() {
		return listData == null ? 0 : listData.size();
	}

	@Override
	public MediaInfo getItem(int position) {
		return listData.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@SuppressLint("InflateParams") @Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(R.layout.item_picture, null);
			holder.user_pic = (ImageView) convertView.findViewById(R.id.item_pic_view);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		Glide.with(context).load(listData.get(position).fileurl_03).dontAnimate()
			.placeholder(R.drawable.imgbtn_photo_selecter).into(holder.user_pic);
		holder.user_pic.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				listener.onClickPhotoPosition(position);
			}
		});
		return convertView;
	}
	
	public interface PicsItemClickListener {
		void onClickPhotoPosition(int sonPosition);
	}

	private class ViewHolder {
		ImageView user_pic;
	}
}
